package com.woniuxy.controller;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.woniuxy.entity.Category;
import com.woniuxy.service.CategoryService;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.woniuxy.dto.PageDto;
import com.woniuxy.entity.Area;
import com.woniuxy.entity.Category;
import com.woniuxy.service.CategoryService;
import com.woniuxy.utils.Result;

@RestController
@RequestMapping("/category")
public class CategoryController {
	@Autowired
	private CategoryService categoryService;
	
	@RequestMapping("/find")
	public PageDto<Category> findAllCategory(Integer page){
		return categoryService.findAllCategory(page);
	}
	
	@GetMapping("findcgname")
	public List<Category> findCategoryOfCgname(){
		return categoryService.findCategoryOfCgname();
	}
	
	@RequestMapping("/add")
	public int addCategory(Category Category) {	
		return categoryService.addCategory(Category);
	}
	
	@RequestMapping("/findCategoryByStatus")
	public PageDto<Category> findCategoryByStatus(Integer status,Integer page){
		return categoryService.findCategoryByStatus(status, page);
	}
	
	@RequestMapping("/search")
	public PageDto<Category> searchCategoryByCgname(String cgname,Integer page){
		System.out.println(categoryService.findCategoryByCgname(cgname, page));
		return categoryService.findCategoryByCgname(cgname, page);	
	}
	
	@RequestMapping("/delete")
	public PageDto<Category> deleteCategoryByCgid(Integer cgid,Integer page){
		categoryService.deleteCategoryByCgid(cgid);
		PageDto<Category> categorys = categoryService.findAllCategory(page);
		return categorys;
	}
	
	@RequestMapping("/updateSwitch")
	public int updateSwitch(Integer cgid, Integer value) {
		return categoryService.updateSwitch(cgid, value);
	}
	

}
